// ==UserScript==
// @include http://*
// @include https://*
// ==/UserScript==

var breakID = "";
var workID = "";

kango.addMessageListener('current_mode', function(event) {
	colour = event.data;
	if (colour == null || colour == "") {
		window.document.body.style.border='';
	} else {
		window.document.body.style.border='25px solid ' + colour;
	}
});

// Get the current mode so it can be set to this page
kango.dispatchMessage('get_mode', '');

kango.addMessageListener('enable_work_notifications', function(event) {
	interval = event.data;
	workID = setInterval(display_work_notification, interval * 60 * 1000);
});

kango.addMessageListener('enable_break_notifications', function(event) {
	interval = event.data;
	breakID = setInterval(display_break_notification, interval * 60 * 1000);
});

kango.addMessageListener('disable_notifications', function(event) {
	if (breakID != "") {
		clearInterval(breakID);
	} else if (workID != "") {
		clearInterval(workID);
	}
});

kango.addMessageListener('display_work_notification', function(event) {
	display_work_notification;
});

kango.addMessageListener('display_break_notification', function(event) {
	display_break_notification;
});

function display_work_notification() {
	newwindow = window.open('','online_manager_work_notification','height=300,width=300');
	newwindow.document.open();
	newwindow.document.write('<html><head></head><body style="text-align: center;"><img src="http://www.pictureshoster.com/files/dttpw90slbuag2h6p7sj.png" alt=""><p>Hey, you have worked hard. You deserve a break.</p></body></html>');
	newwindow.document.close();
	if (window.focus) {
		newwindow.focus();
	}
}

function display_break_notification() {
	newwindow = window.open('','online_manager_break_notification','height=300,width=300');
	newwindow.document.open();
	newwindow.document.write('<html><head></head><body style="text-align: center;"><img src="http://www.pictureshoster.com/files/u9qttbd3inscn428oit.jpg" alt=""><p>Hey, you have been on break. Ready to get back to work?</p></body></html>');
	newwindow.document.close();
	if (window.focus) {
		newwindow.focus();
	}
}
